import { DataTypes } from 'sequelize'
const seq = require('../db/seq')

const CourseModels: any = seq.define('course', {
  id: {
    autoIncrement: true,
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING(45),
    allowNull: false,
    comment: "课程名称"
  },
  introduction: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: "课程简介"
  },
  type: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: "课程类别的id",
    references: {
      model: 'course_type',
      key: 'id'
    }
  },
  teacher: {
    type: DataTypes.STRING(25),
    allowNull: false,
    comment: "老师"
  },
  org_id: {
    type: DataTypes.STRING(45),
    allowNull: false,
    comment: "所属机构的id"
  },
  cover: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: "封面的url地址"
  },
  video_num: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: "视频数量"
  },
  homework_num: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: "作业数量"
  },
  score: {
    type: DataTypes.FLOAT,
    allowNull: true,
    comment: "课程评分"
  },
  level: {
    type: DataTypes.STRING(10),
    allowNull: true,
    comment: "课程等级"
  },
  coursecol: {
    type: DataTypes.STRING(45),
    allowNull: true
  },
  creattime: {
    type: DataTypes.DATEONLY,
    allowNull: true
  }
}, {
  tableName: 'course',
  hasTrigger: true,
  timestamps: false,
  indexes: [
    {
      name: "PRIMARY",
      unique: true,
      using: "BTREE",
      fields: [
        { name: "id" },
      ]
    },
    {
      name: "FK_course_type_id_idx",
      using: "BTREE",
      fields: [
        { name: "type" },
      ]
    },
  ]
});

module.exports = CourseModels